import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import css from '@/assets/css.css'
import root from '@/assets/root.css'
import iconfont from '@/utils/iconfont.js'

import Video from 'video.js'
import ElementUI from 'element-ui';
import 'video.js/dist/video-js.css'
import 'element-ui/lib/theme-chalk/index.css';
import axios from "axios"
import url from "@/url/url.js";

Vue.use(ElementUI);
Vue.use(iconfont)

Vue.prototype.$bus = new Vue();
Vue.prototype.$http = axios;
Vue.prototype.$url = url;
Vue.prototype.$video = Video
Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
    console.log(to.path, from.path);
    // if (to.name == 'VideoList') {
    //     if (to.path !== from.path) {
    //         location.reload();
    //     }
    // }
    next();
});

//JS Date格式化为yyyy-MM-dd类字符串
Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(), //day
        "h+": this.getHours(), //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
                RegExp.$1.length == 1 ? o[k] :
                ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

Vue.prototype.$formatDuring = function(mss) {

    var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));

    var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));

    var seconds = ((mss % (1000 * 60)) / 1000).toFixed(0);

    var h = hours > 10 ? hours : '0' + hours;
    var m = minutes > 10 ? minutes : '0' + minutes;
    var s = seconds > 10 ? seconds : '0' + seconds;

    //return h + " : " + m + " : " + s;
    return m + " : " + s;

}

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')